package com.arvin.service.serviceImpl;

import com.arvin.mapper.ExemptMapper;
import com.arvin.mapper.StudentMapper;
import com.arvin.pojo.Contest;
import com.arvin.pojo.Exempt;
import com.arvin.pojo.ExemptInfo;
import com.arvin.pojo.PageBean;
import com.arvin.service.ExemptService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class ExemptServiceImpl implements ExemptService {

    @Autowired
    private ExemptMapper exemptMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 修改免试申请状态
     * @param exemId
     * @param exemState
     */
    @Override
    public void updateExemState(Integer exemId, String exemState) {
        Exempt exempt = new Exempt();
        exempt.setExemId(exemId);
        exempt.setExemState(exemState);
        exemptMapper.updateExemInfo(exempt);
    }

    /**
     * 获取免试人员名单
     * @param page
     * @param pageSize
     * @param studentId
     * @param stuName
     * @param className
     * @param exemDate
     * @param exemState
     * @return
     */
    @Override
    public PageBean getExemInfo(Integer page, Integer pageSize, String studentId, String stuName,
                                String className,LocalDate exemDate, String exemState,Integer exemScore) {
        PageHelper.startPage(page,pageSize);
        List<ExemptInfo> exemptInfoList = exemptMapper.getExemInfo(exemDate,exemState,studentId,stuName,className,exemScore);
        for (ExemptInfo exemptInfo: exemptInfoList){
            List<Contest> list = studentMapper.findByStudentIdToContest(exemptInfo.getStudentId());
            exemptInfo.setContest(list);
        }
        Page<ExemptInfo> exemptInfoPage = (Page<ExemptInfo>) exemptInfoList;
        PageBean pageBean = new PageBean(exemptInfoPage.getTotal(),exemptInfoPage.getResult());
        return pageBean;
    }

    /**
     * 设置免试通过后的面试分数
     * @param exempt
     */
    @Override
    public void setExemScore(Exempt exempt) {
        exemptMapper.setExemScore(exempt);
    }

    /**
     * 学生免试中面试批量合格和不合格
     * @param ids
     * @param exemState
     */
    @Override
    public void passByExemIds(List<Integer> ids, String exemState) {
        exemptMapper.updateStateByIds(ids,exemState);
    }
}
